package com.ruoyi.web.controller.memberCoupon;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Vouchers;
import com.ruoyi.system.service.IVouchersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 代金券配置 Controller
 *
 * @author ruoyi
 * @date 2025-05-23
 */
@Api(tags="代金券配置")
@RestController
@RequestMapping("/system/vouchers")
public class VouchersController extends BaseController
{
    @Autowired
    private IVouchersService vouchersService;

    /**
     * 查询代金券配置列表
     */
    @ApiOperation("查询代金券配置列表")
    @PreAuthorize("@ss.hasPermi('system:vouchers:list')")
    @GetMapping("/list")
    public TableDataInfo list(Vouchers vouchers)
    {
        startPage();
        List<Vouchers> list = vouchersService.selectVouchersList(vouchers);
        return getDataTable(list);
    }

    /**
     * 导出代金券配置列表
     */
    @ApiOperation("导出代金券配置列表")
    @PreAuthorize("@ss.hasPermi('system:vouchers:export')")
    @Log(title = "代金券配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Vouchers vouchers)
    {
        List<Vouchers> list = vouchersService.selectVouchersList(vouchers);
        ExcelUtil<Vouchers> util = new ExcelUtil<Vouchers>(Vouchers.class);
        util.exportExcel(response, list, "代金券配置数据");
    }

    /**
     * 通过id获取代金券配置详细信息
     */
    @ApiOperation("通过id获取代金券配置详细信息")
    @PreAuthorize("@ss.hasPermi('system:vouchers:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(vouchersService.selectVouchersById(id));
    }

    /**
     * 新增代金券配置
     */
    @ApiOperation("新增代金券配置")
    @PreAuthorize("@ss.hasPermi('system:vouchers:add')")
    @Log(title = "代金券配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Vouchers vouchers)
    {
        return toAjax(vouchersService.insertVouchers(vouchers));
    }

    /**
     * 修改代金券配置
     */
    @ApiOperation("修改代金券配置")
    @PreAuthorize("@ss.hasPermi('system:vouchers:edit')")
    @Log(title = "代金券配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Vouchers vouchers)
    {
        return toAjax(vouchersService.updateVouchers(vouchers));
    }

    /**
     * 通过id批量删除代金券配置信息
     */
    @ApiOperation("通过id批量删除代金券配置信息")
    @PreAuthorize("@ss.hasPermi('system:vouchers:remove')")
    @Log(title = "代金券配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(vouchersService.deleteVouchersByIds(ids));
    }
}
